<template>
  <div class="app-container">
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['oa:mydraftEntity:remove']"
        >删除</el-button>
      </el-col>
    </el-row>

    <el-table v-loading="loading" :data="mydraftEntityList" @row-click="OpenDoc">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="起草时间" align="center" prop="writedate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.writedate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="文件标题" align="center" prop="subject" />

    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
import { listMydraftEntity, getMydraftEntity} from "@/api/oa/mydraftEntity";

export default {
  name: "MydraftEntity",
  components: {
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // VIEW表格数据
      mydraftEntityList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        subject: null,
        writedate: null,
        readers: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        subject: [
          { required: true, message: "文件标题不能为空", trigger: "blur" }
        ],
        writedate: [
          { required: true, message: "起草时间不能为空", trigger: "blur" }
        ],
        readers: [
          { required: true, message: "读者权限不能为空", trigger: "blur" }
        ]
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询VIEW列表 */
    getList() {
      this.loading = true;
      this.queryParams.readers=this.$store.getters.name;
      console.log("this.$store.getters.name:"+this.queryParams.readers);
      listMydraftEntity(this.queryParams).then(response => {
        this.mydraftEntityList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        subject: null,
        writedate: null,
        readers: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },

    /** 删除按钮操作 */
    handleDelete(row) {
      const subjects = row.subject || this.ids;
      this.$confirm('是否确认删除VIEW编号为"' + subjects + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delMydraftEntity(subjects);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        })
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有VIEW数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return exportMydraftEntity(queryParams);
        }).then(response => {
          this.download(response.msg);
        })
    },
    /**打开工单*/
    OpenDoc(row){
      console.log("OpenDoc:",row);
      // this.$router.replace('/myTask/Todo');
      this.$router.push({path: '/fwgl/form/' + row.docunid});
      // this.$router.push({name:"/myTask/Todo",params:{docUnid:row.docUnid}});
    }
  }
};
</script>
